from airconfig.config import config
from django.urls import path, include
from django.http import HttpResponse, JsonResponse
from scheduler.scheduler import Request
from datetime import datetime
# Create your models here.
# 房间
class Room():
    def __init__(self):
        self.roomid=config.room_list[0]
        self.checkinT=datetime.datetime.now()
        self.onoff=0 #0是关机，1是开机
        self.mode=config.default_work_mode
        self.totalCost=0
        self.freeRate=config.fee_rates
        self.default_TargetTemp=config.room_temp
        self.temp_highLimit=config.hot_sup
        self.temp_lowLimit=config.low_sub
        self.default_FanSpeed=config.default_fan_speed
        self.lastoff=None
        self.currenttemp=config.default_current_temp
    def get_current_temp(self):
        if self.lastoff==None:
            self.currenttemp=config.default_current_temp
        else:
            pass_minute=((datetime.now()-self.lastoff).seconds)/60
            if self.currenttemp>=config.default_current_temp:  #加热回温
                temp=self.currenttemp-pass_minute*config.temp_rate
                if temp<config.default_current_temp:
                    self.currenttemp=config.default_current_temp
                else:
                    self.currenttemp=temp
            else:      #降温回温
                temp = self.currenttemp + pass_minute * config.temp_rate
                if temp > config.default_current_temp:
                    self.currenttemp = config.default_current_temp
                else:
                    self.currenttemp = temp
# 顾客
class Customer():
    def login(self):
        123

# 控制器
class Customer_Controller():
    def get_request(self):
        urlpatterns = [
            path('', self.),
            path('poweron', self.poweron),
            path('changetargettemp',self.changetargettemp)
        ]
    def changetargettemp(self,request):
        request.params = json.loads(request.body)
        roomid = request.params['roomid']
        targetTemp=request.params['targetTemp']
        temp=Request()
        request_search=temp.get_request(roomid)
        request_search.targetTemp=targetTemp

    def poweron(self,request):
        request.params = json.loads(request.body)
        roomid = request.params['roomid']
        targetTemp = request.params['targetTemp']
        fanspeed=request.params['fanSpeed']
        for room in room_list:
            if room.roomid==roomid:
                currenttemp=room.get_current_temp()
                request_on= Request(roomid,currenttemp,targetTemp,fanspeed,config.fee_rates[int(fanspeed)])
                # 调用schedule
              


